package com.paas.form.core.element.control.impl.searchItem;

import com.paas.common.util.BeanUtil;
import com.paas.common.util.StringUtil;
import com.paas.form.core.element.base.Utilmethod;
import com.paas.form.core.element.control.FormItem;
import com.paas.form.core.element.field.FieLdsModel;
import com.paas.form.core.element.jsContent.ScriptContent;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;


@Data
public class DivItem implements FormItem {
    private FieLdsModel field;
    private String htmlType;

    public DivItem(FieLdsModel field, String htmlType){
        this.field = field;
        this.htmlType = htmlType;

    }
    public String MakeJsData(){
        String dataStr = "";
        if(BeanUtil.isNotEmpty(this.field) && StringUtil.isNotEmpty(this.field.getColumnOptions())){
            dataStr= dataStr +"\n                ${field.vModel}attrColumnOptions : JSON.parse('${field.columnOptions}'), ";
        }
        return dataStr;
    }


    @Override
    public String makeVue() {
        String elementStart = "<" +this.field.getConfig().getTag() + " v-model=\"${formObject}.${field.vModel}\"  ";
        String attrsStr = Utilmethod.attriAdd(this.field);
        if(BeanUtil.isNotEmpty(this.field) && StringUtil.isNotEmpty(this.field.getColumnOptions())){
            attrsStr= attrsStr +":columnOptions=\"${field.vModel}attrColumnOptions\"";
        }
        String elementEnd = "   ></" + this.field.getConfig().getTag() +">\n";
        String element= elementStart +attrsStr +elementEnd;
        return element;
    }

    @Override
    public ScriptContent makeJs() {
        ScriptContent scriptContent = new ScriptContent();
        scriptContent.setData(this.MakeJsData());
        return scriptContent;
    }
}
